﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLogic.DTO;
using BusinessLogic.Repository_Logic.Interfaces;

namespace TestSystem.Controllers.Administrator
{
    public class PositionController : Controller
    {
        private IPositionRepositoryLogic _positionRepositoryLogic;

        public PositionController(IPositionRepositoryLogic positionRepositoryLogic)
        {
            _positionRepositoryLogic = positionRepositoryLogic;
        }

        public ActionResult Index()
        {
            return View(_positionRepositoryLogic.GetAllPositions());
        }

        public ActionResult AddPosition()
        {
            return View(_positionRepositoryLogic.GetEmptyPositionDTO());
        }

        public string Save(PositionDTO positionDto)
        {
            _positionRepositoryLogic.SavePosition(positionDto);
            return Url.Action("Index");
        }

        public void Update(int id)
        {
            _positionRepositoryLogic.UpdateRecruitmentStatus(id);
        }

        [HttpPost]
        public ActionResult Remove(int id)
        {
            _positionRepositoryLogic.RemovePosition(id);

            var results = new 
            {
                Message = "Pomyślnie usunięto stanowisko.",
                ItemCount = _positionRepositoryLogic.PositionAmount(),
                DeleteId = id
            };
            return Json(results);
        }
    }
}
